package com.hexiang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hexiang.entity.UserInfo;
import com.hexiang.mapper.UserInfoMapper;
import com.hexiang.service.UserInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Title class UserInfoServiceImpl
 */
@Service
@Slf4j
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoService {

    @Resource
    private UserInfoMapper userInfoMapper;

    @Override
    public void testOptimisticLocker() {

        UserInfo userInfo = userInfoMapper.selectById(1);
        log.info("初始的userInfo={}", userInfo);
        userInfo.setVersion(2);
        userInfo.setPhone("13611112222");
        QueryWrapper<UserInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("version", 1);
        wrapper.eq("id",userInfo.getId());
        userInfoMapper.update(userInfo, wrapper);
        UserInfo userInfo2 = userInfoMapper.selectById(1);
        log.info("更新后的userInfo={}", userInfo2);
    }

}
